package com.zzl.bonds.ticket.controller;

import java.util.Arrays;
import java.util.Map;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import com.zzl.general.common.exception.SysException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;

import com.zzl.bonds.ticket.entity.CredirecordEntity;
import com.zzl.bonds.ticket.dto.CredirecordAddDto;
import com.zzl.bonds.ticket.dto.CredirecordUpdateDto;
import com.zzl.bonds.ticket.service.CredirecordService;
/**
 * 授信修改记录
 *
 * @author gull
 * @date 2022-09-14 09:31:58
 */
@ApidocController("授信修改记录")
@RestController
@SuppressWarnings("javadoc")
    @RequestMapping("ticket/credirecord")
    @Slf4j
public class CredirecordController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private CredirecordService credirecordService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询授信修改记录数据", operationId = "ticket/credirecord" + "/list")
    @ApidocReturnPage(genericTypeClass = CredirecordEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params) {
        PageUtils page = credirecordService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取授信修改记录数据", operationId = "ticket/credirecord" + "/info/id")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "data", valueClass = CredirecordEntity.class)
    })
    public Result info(@ApidocParam(description = "授信修改记录id", name = "id", required = true) @PathVariable("id") String id) {
        CredirecordEntity credirecord = credirecordService.getById(id);
        return Result.ok().put("data", credirecord);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApidocOperation(description = "保存授信修改记录", operationId = "ticket/credirecord" + "/save")
    @ApidocReturnR
    public Result save(@ApidocParam(description = "保存的授信修改记录对象值", name = "credirecord", required = true) @RequestBody CredirecordAddDto credirecord) {
        try {
            credirecordService.saveCredirecord(credirecord, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApidocOperation(description = "修改授信修改记录", operationId = "ticket/credirecord" + "/update")
    @ApidocReturnR
    public Result update(@ApidocParam(description = "修改的授信修改记录对象值", name = "credirecord", required = true) @RequestBody CredirecordUpdateDto credirecord) {
        try {
            credirecordService.updateCredirecordById(credirecord, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApidocOperation(description = "删除授信修改记录", operationId = "ticket/credirecord" + "/delete")
    @ApidocReturnR
    public Result delete(@ApidocParam(description = "删除的授信修改记录对象id集合", name = "ids", required = true) @RequestBody String[] ids) {
        credirecordService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
